package org.example;

import com.antgroup.geaflow.common.config.Configuration;
import com.antgroup.geaflow.env.Environment;
import com.antgroup.geaflow.env.EnvironmentFactory;
import com.antgroup.geaflow.pipeline.IPipelineResult;
import com.antgroup.geaflow.pipeline.Pipeline;
import com.antgroup.geaflow.pipeline.PipelineFactory;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.example.cases.sf1.Case1Pipeline;
import org.example.cases.sf1.Case23Pipeline;
import org.example.cases.sf1.Case4Pipeline;
import org.example.constants.Constants;

public class Main {

    private static Pipeline pipeline;

    public static void main(String[] args) {

        Logger.getLogger("stdout").setLevel(Level.OFF);
        Logger.getRootLogger().setLevel(Level.OFF);

        // long st = System.currentTimeMillis();
        Environment environment = EnvironmentFactory.onLocalEnvironment();
        pipeline = PipelineFactory.buildPipeline(environment);
        Configuration envConfig = environment.getEnvironmentContext().getConfig();
        envConfig.put(Constants.OUTPUT_DIR, args[1]);

        IPipelineResult<?> result = addTaskToPipeline(args);
        result.get();
        environment.shutdown();
        // long ed = System.currentTimeMillis();
        // System.out.println("cost time: " + (ed - st) + " ms");
    }

    public static IPipelineResult<?> addTaskToPipeline(String[] args) {

        new Case4Pipeline(args[0], pipeline).submit();
        new Case1Pipeline(args[0], pipeline).submit();
        new Case23Pipeline(args[0], pipeline).submit();

        return pipeline.execute();
    }
}
